import React, { memo } from 'react';
import { SchemaForm } from 'gantd';
import type { UISchema, TitleSchema, Schema } from 'gantd/lib/schema-form';
const defaultSpan = 24; //默认栅格占位格数

export interface SchemaAllProps {
  schema?: Schema;
  uiSchema?: UISchema;
  titleConfig?: TitleSchema;
  values?: object;
}
export interface FormContentProps extends SchemaAllProps {
  formRef: any;
  span: number;
}

const FormContent = memo((props: FormContentProps) => {
  const { formRef, schema, uiSchema = {}, values = {}, span = defaultSpan, titleConfig, ...restProps } = props;

  return (
    <SchemaForm
      wrappedComponentRef={formRef}
      data={values}
      schema={schema}
      uiSchema={{
        'ui:labelCol': {},
        'ui:wrapperCol': {},
        'ui:col': { span: span },
        ...uiSchema,
      }}
      titleConfig={{
        'title:visible': false,
        ...titleConfig,
      }}
      {...restProps}
    />
  );
});
export default FormContent;
